package com.jindu.kernel.message;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.afs.model.v20180112.AuthenticateSigRequest;
import com.aliyuncs.afs.model.v20180112.AuthenticateSigResponse;

/**
 * @author jarvis
 */
public class SlideVerification {

    private String regionid = "cn-hangzhou";
    private String accessKeyId = "LTAIdcl2Br3YcV8M";
    private String accessKeySecret = "mFvMeMpgfskLP9FFsI8rl62jZ8VkiH";

    private String appKey="FFFF0N00000000005CAB";
    private String remoteIp="8.8.8.8";

    IAcsClient client = null;
    boolean successVerification=false;

    public SlideVerification() throws ClientException {
        //Create a new IClientProfile instance
        IClientProfile profile= DefaultProfile.getProfile(regionid, accessKeyId, accessKeySecret);
        client = new DefaultAcsClient(profile);

        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "afs", "afs.aliyuncs.com");
    }

    public boolean verificationSlide(String sessionId,String sig,String token,String scene){
        AuthenticateSigRequest request = new AuthenticateSigRequest();
        request.setSessionId(sessionId);
        request.setSig(sig);
        request.setToken(token);
        request.setScene(scene);

        request.setAppKey(appKey);
        request.setRemoteIp(remoteIp);

        try {
            AuthenticateSigResponse response = client.getAcsResponse(request);
            if(response.getCode()== 100) {
                //验签通过
                successVerification=true;
            } else {
                //验签失败
                successVerification=false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return successVerification;
    }





}
